import request from "@/utils/request";

const LOG_BASE_URL = "/v3/manager/upgradePack";

class UpgradeAPI {
  static editSave(queryParams: UpgradeFormData) {
    return request({
      url: `${LOG_BASE_URL}/update`,
      method: "put",
      headers: {
        "Content-Type": "application/json",
      },
      data: queryParams,
    });
  }
  static addUpgradePack(queryParams: UpgradeFormData) {
    return request({
      url: `${LOG_BASE_URL}/save`,
      method: "post",
      headers: {
        "Content-Type": "application/json",
      },
      data: queryParams,
    });
  }
  static page(queryParams: UpgradePageQuery) {
    return request<any, PageVO>({
      url: `${LOG_BASE_URL}/page`,
      method: "post",
      headers: {
        "Content-Type": "application/json",
      },
      data: queryParams,
    });
  }
  static searchID(id: string) {
    return request<any, UpgradeFormData>({
      url: `${LOG_BASE_URL}/id/${id}`,
      method: "get",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    });
  }
  /**
   * 删除设备类型
   *
   * @param queryParams 查询参数
   */
  static deleteSave(queryParams: string) {
    return request({
      url: `${LOG_BASE_URL}/delete/${queryParams}`,
      method: "delete",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    });
  }

  static downloadOTA(queryParams: downloadOV) {
    return request<any, PageVO>({
      url: `/v3/manager/download/downloadOTA`,
      method: "post",
      headers: {
        "Content-Type": "application/json",
      },
      data: queryParams,
    });
  }

  static deviceCancelSave(id: string) {
    return request({
      url: `v3/manager/upgradeSet/cancel/${id}`,
      method: "delete",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    });
  }
}

export default UpgradeAPI;

/**
 * 分页
 */
export interface UpgradePageQuery {
  /** 搜索关键字 */
  pages?: any;
  upgradeName?: string;
  customerId?: string;
}
/**
 * 分页VO
 */
export interface PageVO {
  current: number;
  pages: number;
  records: Array<any>;
  size: number;
  total: number;
}
export interface UpgradeFormData {
  id?: string;
  upgradeName: string;
  manufacturer: string;
  module: string;
  softVer: string;
  url: string;
  remark: string;
  md5?: string;
}
export interface downloadOV {
  deviceId: string;
  upgradePackId: string;
  type: string;
  time: string;
}
